package wiki.hitime.demo.test.service;

import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import wiki.hitime.demo.test.enums.CalcTypeEnum;
import wiki.hitime.demo.test.util.ContextUtil;

/**
 * @author zhangdaoping
 * @create 2019-10-31 15:08
 */
@Service
public class ImplLoadService {

    /**
     * 根据类型计算结果
     *
     * @param a            值a
     * @param b            值b
     * @param calcTypeEnum 计算类型
     * @return 计算结果
     */
    public int loadCalcResult(int a, int b, CalcTypeEnum calcTypeEnum) {
        BaseCalcServiceFactory baseCalcServiceFactory = null;
        switch (calcTypeEnum) {
            case ADD: {
                baseCalcServiceFactory = (BaseCalcServiceFactory) ContextUtil.getBean("addCalcServiceImpl");
            }
            break;
            case SUBTRACT: {
                baseCalcServiceFactory = (BaseCalcServiceFactory) ContextUtil.getBean("subtractCalcServiceImpl");
            }
            break;
            default:
        }
        Assert.notNull(baseCalcServiceFactory, "没有找到对应计算类");
        return baseCalcServiceFactory.calc(a, b);
    }
}
